﻿#region Usings

using PolyGameEngine.GamePieces;
using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion

namespace PolyMorph.CustomGamePieces
{
    public class Teleporter :SensorForceTile 
    {
        Vector2 outPos;
        Texture2D outSprite;
        int OutCounter = 0;
        int OutCounterStop;
        int OutDivideBy;

        public Teleporter(PhysicsGame PhysicsGame, World World,Material Material, Texture2D InSprite, Texture2D OutSprite,Vector2 InPos, Vector2 OutPos, int SaveLineIndex)
            :base(PhysicsGame, World, Material, InSprite, 1, InPos, 0, 0, 1, SaveLineIndex, "Teleport",0)
        {
            outPos = OutPos;
            outSprite = OutSprite;

            OutCounterStop = (outSprite.Width / 50) * 1;
            OutDivideBy = 1;
            ShouldRequestAccess = false;
        }

        public override void Effect()
        {
            if (Vector2.Distance(GamePieceInEffect.position, position) < 25)
            {
                AudioMan.PlayCue("Teleport");
                if (GamePieceInEffect.GetType().IsSubclassOf(typeof(Unit)))
                    ((Unit)GamePieceInEffect).canJump = false;
                GamePieceInEffect.Velocity = Vector2.Zero;
                GamePieceInEffect.position = outPos;
                GamePiece._ScreenOffset = outPos;
            }
        }


        public override void Update(GameTime gameTime)
        {
            ShouldRequestAccess = false;
            if (++OutCounter >= OutCounterStop)
                OutCounter = 0;
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            Rectangle frame = new Rectangle(50 * (OutCounter / OutDivideBy), 0, 50, 50);
            Vector2 origin = new Vector2(25, 25);
            spriteBatch.Draw(outSprite, outPos + _ScreenOffset, frame, Color.White, rotation, origin, 1, SpriteEffects.None, drawingDepth);
            base.Draw(gameTime);
        }
        
    }



}





/*
 public void addGamePiece(GamePiece GamePiece)
        {
            GamePiece.Initialize();
            Components.Add(GamePiece);
            gamePieces.Add(GamePiece);
        }
*/